home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 27.4 KB | 989 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: DrawSel.cpp
- // Release Version: $ ODF 2 $
- //
- // Author: Henri Lamiraux
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "ODFDraw.hpp"
-
- #ifndef DRAWSEL_H
- #include "DrawSel.h"
- #endif
-
- #ifndef DRAWCONT_H
- #include "DrawCont.h"
- #endif
-
- #ifndef DRAWFRM_H
- #include "DrawFrm.h"
- #endif
-
- #ifndef DRAWPART_H
- #include "DrawPart.h"
- #endif
-
- #ifndef BASESHP_H
- #include "BaseShp.h"
- #endif
-
- #ifndef BOUNDSHP_H
- #include "BoundShp.h"
- #endif
-
- #ifndef LINESHP_H
- #include "LineShp.h"
- #endif
-
- #ifndef OVALSHP_H
- #include "OvalShp.h"
- #endif
-
- #ifndef RECTSHP_H
- #include "RectShp.h"
- #endif
-
- #ifndef RRECTSHP_H
- #include "RRectShp.h"
- #endif
-
- #ifndef TEXTSHP_H
- #include "TextShp.h"
- #endif
-
- #ifndef DRAWCLIP_H
- #include "DrawClip.h"
- #endif
-
- #ifndef DRAWPRXY_H
- #include "DrawPrxy.h"
- #endif
-
- #ifndef UTILS_H
- #include "Utils.h"
- #endif
-
- #ifndef SHPTRAKR_H
- #include "ShpTrakr.h"
- #endif
-
- #ifndef DRAWCMDS_H
- #include "DrawCmds.h"
- #endif
-
- #ifndef DRAWLINK_H
- #include "DrawLink.h"
- #endif
-
- #ifndef DRWPRMSE_H
- #include "DrwPrmse.h"
- #endif
-
- // ----- Part Layer -----
-
- #ifndef FWCONTXT_H
- #include "FWContxt.h"
- #endif
-
- #ifndef FWSESION_H
- #include "FWSesion.h"
- #endif
-
- #ifndef FWITERS_H
- #include "FWIters.h"
- #endif
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWPRESEN_H
- #include "FWPresen.h"
- #endif
-
- #ifndef FWKIND_H
- #include "FWKind.h"
- #endif
-
- // ----- OS Layer -----
-
- #ifndef FWORDCOL_H
- #include "FWOrdCol.h"
- #endif
-
- #ifndef FWSUSINK_H
- #include "FWSUSink.h"
- #endif
-
- #ifndef FWODGEOM_H
- #include "FWODGeom.h"
- #endif
-
- #ifndef FWEVENT_H
- #include "FWEvent.h"
- #endif
-
- #ifndef SLMixOS_H
- #include "SLMixOS.h"
- #endif
-
- // ----- Foundation Includes -----
-
- #ifndef FWSTREAM_H
- #include "FWStream.h"
- #endif
-
- #ifndef FWSOMENV_H
- #include "FWSOMEnv.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_ODShape_xh
- #include <Shape.xh>
- #endif
-
- #ifndef SOM_ODStorageUnit_xh
- #include <StorageU.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdTypes_defined
- #include <StdTypes.xh>
- #endif
-
- //========================================================================================
- // Runtime Informations
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odfdraw2
- #endif
-
- //========================================================================================
- // class CDrawSelection
- //========================================================================================
-
- FW_DEFINE_AUTO(CDrawSelection)
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::CDrawSelection
- //----------------------------------------------------------------------------------------
-
- CDrawSelection::CDrawSelection(Environment* ev, CDrawPart* drawPart):
- FW_CSelection(ev, TRUE, TRUE),
- fDrawPart(drawPart),
- fUpdateShape(NULL),
- fFrozenCount(0),
- fCount(0),
- fSelectionContent(NULL),
- fWorkingHandle(FW_kZeroRect, FW_kFill),
- fDraggedContent(NULL)
- {
- fSelectionContent = FW_NEW(CDrawSelectionContent, (ev, drawPart, this));
- fWorkingHandle.SetInk(FW_kInvertInk);
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::~CDrawSelection
- //----------------------------------------------------------------------------------------
-
- CDrawSelection::~CDrawSelection()
- {
- FW_START_DESTRUCTOR
- if (fUpdateShape)
- {
- FW_SOMEnvironment ev;
- fUpdateShape->Release(ev);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::GetSelectedContent
- //----------------------------------------------------------------------------------------
-
- FW_CContent* CDrawSelection::GetSelectedContent(Environment* ev)
- {
- FW_UNUSED(ev);
- return fSelectionContent;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::WhichHandle
- //----------------------------------------------------------------------------------------
-
- CBaseShape* CDrawSelection::WhichHandle(Environment* ev, FW_CGraphicContext& gc, const FW_CPoint& mouse, short& whichHandle, FW_Fixed zoomFactor) const
- {
- FW_UNUSED(ev);
- whichHandle = 0;
-
- if (fCount != 0)
- {
- CDrawContentShapeIterator ite(fSelectionContent);
- for (CBaseShape *shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
- {
- whichHandle = shape->WhichHandle(gc, mouse, zoomFactor);
- if (whichHandle != 0)
- return shape;
- }
- }
-
- return NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::RenderSelectionHandles
- //----------------------------------------------------------------------------------------
-
- void CDrawSelection::RenderSelectionHandles(Environment* ev, FW_CGraphicContext& gc, FW_Fixed zoomFactor)
- {
- FW_UNUSED(ev);
- CDrawContentShapeIterator ite(fSelectionContent);
- for (CBaseShape *shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
- {
- shape->RenderHandles(gc, zoomFactor);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::InvalidateSelectionHandles
- //----------------------------------------------------------------------------------------
-
- void CDrawSelection::InvalidateSelectionHandles(Environment* ev, CDrawFrame* frame)
- {
- FW_CSuperView* contentView = frame->GetContentView(ev);
- FW_CAcquiredODShape workingShape = FW_NewODShape(ev);
- FW_Fixed penSize = CalcHandlePenSize(frame->GetZoomFactor());
-
- CDrawContentShapeIterator ite(fSelectionContent);
- for (CBaseShape *shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
- {
- shape->InvalidateHandles(ev, contentView, workingShape, penSize);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::RenderAllHandles
- //----------------------------------------------------------------------------------------
-
- void CDrawSelection::RenderAllHandles(Environment* ev, CDrawFrame* frame)
- {
- if (fCount != 0)
- {
- FW_CFrameFacetIterator ite(ev, frame);
- for (ODFacet* facet = (ODFacet*)ite.First(ev); ite.IsNotComplete(ev); facet = (ODFacet*)ite.Next(ev))
- {
- FW_CViewContext vc(ev, frame->GetContentView(ev), facet);
- RenderSelectionHandles(ev, vc, frame->GetZoomFactor());
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::RenderHandles
- //----------------------------------------------------------------------------------------
-
- void CDrawSelection::RenderHandles(Environment* ev, CBaseShape* shape)
- {
- FW_CPresentationFrameIterator ite(ev, GetPresentation(ev));
- for (CDrawFrame* frame = (CDrawFrame*)ite.First(ev); ite.IsNotComplete(ev); frame = (CDrawFrame*)ite.Next(ev))
- {
- if (frame->HasSelectionFocus(ev) && frame->GetWindow(ev)->IsActive(ev))
- {
- FW_CFrameFacetIterator i(ev, frame);
- for (ODFacet* facet = i.First(ev); i.IsNotComplete(ev); facet = i.Next(ev))
- {
- FW_CViewContext vc(ev, frame->GetContentView(ev), facet);
- shape->RenderHandles(vc, frame->GetZoomFactor());
- }
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::CloseSelection
- //----------------------------------------------------------------------------------------
-
- void CDrawSelection::CloseSelection(Environment* ev)
- {
- CBaseShape* shape;
- while ((shape = fSelectionContent->GetFirstShape()) != NULL)
- {
- DoRemove(ev, shape);
- RenderHandles(ev, shape); // turn off
- }
-
- CalcCache(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::AddToSelection
- //----------------------------------------------------------------------------------------
-
- void CDrawSelection::AddToSelection(Environment* ev, CBaseShape* theShape, FW_Boolean renderHandles)
- {
- if (theShape != NULL)
- {
- fDrawPart->SetTool(ev, kSelectTool);
- DoAdd(ev, theShape);
- if (renderHandles)
- RenderHandles(ev, theShape); // Turn on
- }
-
- CalcCache(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::RemoveFromSelection
- //----------------------------------------------------------------------------------------
-
- void CDrawSelection::RemoveFromSelection(Environment* ev, CBaseShape* shape, FW_Boolean renderHandles)
- {
- if (shape != NULL)
- {
- DoRemove(ev, shape);
- if (renderHandles)
- RenderHandles(ev, shape); // Turn Off
- }
-
- CalcCache(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::DoAdd
- //----------------------------------------------------------------------------------------
-
- void CDrawSelection::DoAdd(Environment* ev, CBaseShape *shape)
- {
- fSelectionContent->AddShape(ev, shape);
- this->ShapeAdded(ev, shape);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::ShapeAdded
- //----------------------------------------------------------------------------------------
- void CDrawSelection::ShapeAdded(Environment* ev, CBaseShape* shape)
- {
- shape->SelectShape(ev, true);
- fCount++;
- if (shape->IsFrozen())
- fFrozenCount++;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::DoRemove
- //----------------------------------------------------------------------------------------
-
- void CDrawSelection::DoRemove(Environment* ev, CBaseShape *shape)
- {
- fSelectionContent->RemoveShape(ev, shape);
- shape->SelectShape(ev, false);
- fCount--;
- if (shape->IsFrozen())
- fFrozenCount--;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::ClearSelection
- //----------------------------------------------------------------------------------------
-
- void CDrawSelection::ClearSelection(Environment* ev)
- {
- CBaseShape *shape;
- while ((shape = fSelectionContent->GetFirstShape()) != NULL)
- {
- shape->CheckPromise(ev);
-
- DoRemove(ev, shape); // Remove from selection list
- fDrawPart->RemoveShapeFromPart(ev, shape); // Remove from part
- }
-
- CDrawFacetClipper facetClipper(fDrawPart);
- facetClipper.Clip(ev, GetPresentation(ev), fUpdateShape);
- GetPresentation(ev)->Invalidate(ev, fUpdateShape);
-
- CalcCache(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::SelectAll
- //----------------------------------------------------------------------------------------
-
- void CDrawSelection::SelectAll(Environment* ev)
- {
- CDrawFrame* activeFrame = (CDrawFrame*)fDrawPart->GetLastActiveFrame(ev);
-
- RenderAllHandles(ev, activeFrame);
-
- CDrawContentShapeIterator ite(fDrawPart->GetDrawContent());
- for (CBaseShape *shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
- {
- if (!shape->IsSelectedShape())
- DoAdd(ev, shape);
- }
-
- RenderAllHandles(ev, activeFrame);
-
- CalcCache(ev);
-
- fDrawPart->SetTool(ev, kSelectTool);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::IsEmpty
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CDrawSelection::IsEmpty(Environment* ev) const
- {
- FW_UNUSED(ev);
- return fCount == 0;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::CenterSelection
- //----------------------------------------------------------------------------------------
-
- FW_CPoint CDrawSelection::CenterSelection(Environment* ev, FW_CFrame* scopeFrame)
- {
- FW_ASSERT(scopeFrame);
-
- fDrawPart->SetTool(ev, kSelectTool);
-
- CalcCache(ev);
-
- FW_CRect bounds = scopeFrame->GetContentView(ev)->GetBoundsInContent(ev);
- FW_CRect box(fDragRect);
- box.PlaceInCenterOf(bounds);
-
- FW_CPoint result(box.left - fDragRect.left, box.top - fDragRect.top);
- OffsetSelection(ev, result.x, result.y);
-
- CDrawFacetClipper facetClipper(fDrawPart);
- facetClipper.Clip(ev, GetPresentation(ev), fUpdateShape);
- GetPresentation(ev)->Invalidate(ev, fUpdateShape);
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::Resize
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CDrawSelection::Resize(Environment* ev, const FW_CMouseEvent& theMouseEvent)
- {
- if (fClickedHandle == 0)
- return FALSE;
-
- if (fDrawPart->IsReadOnly(ev)) // can't resize read only part
- return TRUE;
-
- if (!theMouseEvent.WaitUntilMouseMoved(ev))
- return TRUE;
-
- ODFacet* facet = theMouseEvent.GetFacet(ev);
- CDrawFrame *frame = (CDrawFrame*)FW_CFrame::ODtoFWFrame(ev, facet->GetFrame(ev));
-
- CBaseShape* anchorShape = GetAnchorShape();
-
- FW_CInk resizeInk(FW_kRGBBlack, FW_kRGBWhite, FW_kXOr);
- FW_CStyle resizeStyle(anchorShape->GetResizeStyle());
-
- CResizeTracker resizeTracker(ev, frame->GetContentView(ev), facet, anchorShape, fClickedHandle, resizeInk, resizeStyle, TRUE);
- if (resizeTracker.Track(ev, theMouseEvent))
- {
- GetPresentation(ev)->Invalidate(ev, fUpdateShape);
-
- FW_CPoint lastLocation;
- resizeTracker.GetLastLocation(lastLocation);
- FW_CRect srcRect, dstRect;
- anchorShape->GetMapRects(fClickedHandle, lastLocation, srcRect, dstRect);
-
- CResizeShapeCommand* cmd = FW_NEW(CResizeShapeCommand,
- (ev, fDrawPart, frame, this,
- srcRect, dstRect));
- cmd->Execute(ev);
- }
- else
- {
- FW_CViewContext vc(ev, frame->GetContentView(ev), facet);
-
- FW_Fixed penSize = CalcHandlePenSize(frame->GetZoomFactor());
- anchorShape->CalcHandle(fClickedHandle, &fWorkingHandle, penSize);
- fWorkingHandle.Render(vc); // redraw the handle
- }
-
- return TRUE;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::CalcCache
- //----------------------------------------------------------------------------------------
-
- void CDrawSelection::CalcCache(Environment* ev)
- {
- fDragRect.Clear();
-
- if (fUpdateShape == NULL)
- fUpdateShape = ::FW_NewODShape(ev);
-
- if (fCount == 0)
- return;
-
- FW_CAcquiredODShape aqTempShape = ::FW_NewODShape(ev);
- FW_CRect tempRect;
-
- FW_Boolean first = TRUE;
- CDrawContentShapeIterator ite(fSelectionContent);
- for (CBaseShape *shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
- {
- shape->GetDragRect(tempRect);
- shape->GetUpdateBox(ev, aqTempShape);
- if (first)
- {
- fDragRect = tempRect;
- fUpdateShape->CopyFrom(ev, aqTempShape);
- }
- else
- {
- fDragRect |= tempRect;
- fUpdateShape->Union(ev, aqTempShape);
- }
-
- first = FALSE;
- }
-
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::AcquireSelectionShape
- //----------------------------------------------------------------------------------------
-
- ODShape* CDrawSelection::AcquireSelectionShape(Environment* ev, ODFacet* facet, FW_CFrame* frame)
- {
- FW_UNUSED(frame);
- FW_UNUSED(facet);
-
- return ::FW_NewODShape(ev, fDragRect);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::AcquireSelectionOutline
- //----------------------------------------------------------------------------------------
-
- ODShape* CDrawSelection::AcquireSelectionOutline(Environment* ev, ODFacet* facet, FW_CFrame* frame)
- {
- FW_CAcquiredODShape outline;
-
- if (GetAnchorShape() == NULL)
- outline = FW_CopyAndRelease(ev, AcquireSelectionShape(ev, facet, frame));
- else
- outline = GetAnchorShape()->CreateShapeOutline(ev);
-
- if (fCount > 1)
- {
- FW_CAcquiredODShape shapeOutline = FW_CSelection::AcquireSelectionOutline(ev, facet, frame);
- outline->Union(ev, shapeOutline);
- }
-
- return outline.Orphan();
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::OffsetSelection
- //----------------------------------------------------------------------------------------
-
- void CDrawSelection::OffsetSelection(Environment* ev, FW_Fixed xDelta, FW_Fixed yDelta)
- {
- FW_CAcquiredODShape aqUnionShape(fUpdateShape->Copy(ev));
-
- CDrawContentShapeIterator ite(fSelectionContent);
- for (CBaseShape *shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
- {
- shape->OffsetShape(ev, xDelta, yDelta);
- }
-
- CalcCache(ev);
-
- aqUnionShape->Union(ev, fUpdateShape);
-
- CDrawFacetClipper facetClipper(fDrawPart);
- facetClipper.Clip(ev, GetPresentation(ev), aqUnionShape);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::SelectWithRectangle
- //----------------------------------------------------------------------------------------
-
- void CDrawSelection::SelectWithRectangle(Environment* ev, const FW_CMouseEvent& theMouseEvent)
- {
- CRectShape rectShape(fDrawPart); // Create a rect shape on the stack
- FW_CStyle trackStyle(FW_kFixed0, FW_kAntPat);
- FW_CInk trackInk(FW_kRGBBlack, FW_kRGBWhite, FW_kXOr);
- rectShape.ChangeRenderVerb(ev, kFrameOnly);
- rectShape.SetFrameInk(trackInk);
- rectShape.SetFrameStyle(trackStyle);
-
- ODFacet* facet = theMouseEvent.GetFacet(ev);
- FW_CFrame *frame = FW_CFrame::ODtoFWFrame(ev, facet->GetFrame(ev));
-
- CShapeTracker tracker(ev, frame->GetContentView(ev), facet, &rectShape, FALSE);
- if (tracker.Track(ev, theMouseEvent))
- {
- FW_Boolean isShift = theMouseEvent.IsExtendModifier(ev);
- FW_CRect selectRect = rectShape.GetRectGeometry();
-
- CDrawContentShapeIterator ite(fDrawPart->GetDrawContent());
- for (CBaseShape *shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
- {
- if (shape->InSelectionRect(selectRect))
- {
- if (shape->IsSelectedShape())
- {
- if (isShift)
- {
- DoRemove(ev, shape);
- RenderHandles(ev, shape); // Turn Off
- }
- }
- else
- {
- DoAdd(ev, shape);
- RenderHandles(ev, shape); // Turn on
- }
- }
- else if (shape->IsSelectedShape() && !isShift)
- {
- DoRemove(ev, shape);
- RenderHandles(ev, shape); // Turn Off
- }
- }
- CalcCache(ev);
- }
- else
- {
- if (!theMouseEvent.IsExtendModifier(ev))
- CloseSelection(ev);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::SetFrozen
- //----------------------------------------------------------------------------------------
-
- void CDrawSelection::SetFrozen(Environment* ev, FW_Boolean state)
- {
- FW_UNUSED(ev);
- CDrawContentShapeIterator ite(fSelectionContent);
- for (CBaseShape *shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
- {
- if (shape->SetFrozen(state))
- {
- state ? fFrozenCount++ : fFrozenCount--;
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::SelectionChanged
- //----------------------------------------------------------------------------------------
-
- void CDrawSelection::SelectionChanged(Environment* ev, ODUpdateID updateID)
- {
- CDrawPublishLinkCollection temp;
-
- CDrawContentShapeIterator ite(fSelectionContent);
- for (CBaseShape *shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
- {
- if (shape->IsPublished())
- {
- if (!temp.Contains(shape->GetPublishLink()))
- temp.AddLast(shape->GetPublishLink());
- }
- }
-
- CDrawPublishLinkCollectionIterator tempIte(&temp);
- for (CDrawPublishLink* link = tempIte.First(); tempIte.IsNotComplete(); link = tempIte.Next())
- {
- link->ContentUpdated(ev, updateID);
- }
-
- temp.RemoveAll();
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::IsSelectionLinkable
- //----------------------------------------------------------------------------------------
- // Don't write a link spec if any of the selected shapes is in a link destination
-
- FW_Boolean CDrawSelection::IsSelectionLinkable(Environment* ev)
- {
- FW_Boolean result = TRUE;
-
- CDrawContentShapeIterator ite(fSelectionContent);
- for (CBaseShape *shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
- {
- if (shape->IsInLinkDestination(ev))
- {
- result = FALSE;
- break;
- }
- else if (shape->IsPublished()) // don't allow a shape to be published more than once
- {
- result = FALSE;
- break;
- }
- }
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::CanPasteAsLink
- //----------------------------------------------------------------------------------------
- FW_Boolean CDrawSelection::CanPasteAsLink(Environment* ev, ODPasteAsMergeSetting& setting,
- ODStorageUnit* su)
- {
- // Check whether the storage unit contains mergeable content
- if (su->Exists(ev, kODPropContents, fDrawPart->GetPartKind(ev)->GetType(ev), 0))
- {
- if (su->Exists(ev, kODPropContentFrame, kODWeakStorageUnitRef, 0))
- setting = kODPasteAsEmbed;
- else
- setting = kODPasteAsMerge;
- }
- else // foreign content - cannot be merged
- setting = kODPasteAsEmbedOnly;
-
- return fAllowLink;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::IsMouseInDraggableItem
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CDrawSelection::IsMouseInDraggableItem(Environment* ev, FW_CFrame* frame,
- const FW_CMouseEvent& theMouseEvent,
- FW_Boolean inBackground)
- {
- fClickedHandle = 0;
- fAnchorShape = NULL;
-
- if (!inBackground && fDrawPart->GetTool() != kSelectTool)
- return FALSE;
-
- FW_CViewContext vc(ev, frame->GetContentView(ev), theMouseEvent.GetFacet(ev));
-
- // ----- Look first for a handle -----
- FW_CPoint where = theMouseEvent.GetMousePosition(ev, FW_CMouseEvent::kFrame);
- frame->GetContentView(ev)->FrameToViewContent(ev, where);
-
- CBaseShape* clickedShape = WhichHandle(ev, vc, where, fClickedHandle, ((CDrawFrame*)frame)->GetZoomFactor());
- if (clickedShape != NULL)
- {
- fAnchorShape = clickedShape;
- return FALSE; // if in a handle we won't drag
- }
-
- // ----- then look for a selected shape -----
- CBaseShape* shape = fDrawPart->WhichShape(ev, vc, theMouseEvent, TRUE);
-
- if (shape != NULL && shape->IsSelectedShape())
- {
- fAnchorShape = shape;
- return TRUE;
- }
-
- return FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::UpdateSelectionOnMouseDown
- //----------------------------------------------------------------------------------------
-
- void CDrawSelection::UpdateSelectionOnMouseDown(Environment* ev,
- const FW_CMouseEvent& mouseEvent,
- ODFacet* embeddedFacet,
- FW_Boolean inEmbeddedFrameBorder,
- FW_Boolean inBackground)
- {
- if (inEmbeddedFrameBorder)
- {
- fClickedHandle = 0;
- fAnchorShape = NULL;
-
- CProxyShape *theShape = (CProxyShape*)fDrawPart->GetProxy(ev, embeddedFacet->GetFrame(ev));
- FW_ASSERT(theShape);
-
- if (!theShape->IsSelectedShape())
- AddToSelection(ev, theShape, TRUE);
-
- fAnchorShape = theShape;
- }
- else if (fDrawPart->GetTool() == kSelectTool || inBackground)
- {
- FW_CFrame *frame = FW_CFrame::ODtoFWFrame(ev, mouseEvent.GetFacet(ev)->GetFrame(ev));
- FW_CViewContext vc(ev, frame->GetContentView(ev), mouseEvent.GetFacet(ev));
-
- // ----- First look if we are in a resize handle -----
- FW_CPoint where = mouseEvent.GetMousePosition(ev, FW_CMouseEvent::kFrame);
- frame->GetContentView(ev)->FrameToViewContent(ev, where);
-
- short clickedHandle;
- if (WhichHandle(ev, vc, where, clickedHandle, ((CDrawFrame*)frame)->GetZoomFactor()) != NULL)
- return;
-
- // ----- So now we are not in a handle -----
- CBaseShape* clickedShape = fDrawPart->WhichShape(ev, vc, mouseEvent, FALSE);
- if (clickedShape)
- {
- if (mouseEvent.IsExtendModifier(ev))
- {
- if (clickedShape->IsSelectedShape())
- {
- RemoveFromSelection(ev, clickedShape, !inBackground);
- if (clickedShape == fAnchorShape)
- fAnchorShape = NULL;
- }
- else
- {
- AddToSelection(ev, clickedShape, !inBackground);
- fAnchorShape = clickedShape;
- }
- }
- else if (!clickedShape->IsSelectedShape())
- {
- fAnchorShape = clickedShape;
- CloseSelection(ev);
- AddToSelection(ev, clickedShape, !inBackground);
- }
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::DeleteSelection
- //----------------------------------------------------------------------------------------
- void CDrawSelection::DeleteSelection(Environment* ev)
- {
- CBaseShape *shape;
- while ((shape = fSelectionContent->GetFirstShape()) != NULL)
- {
- DoRemove(ev, shape); // Remove from selection
- fDrawPart->RemoveShapeFromPart(ev, shape); // Remove from part
- delete shape;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::GetLinkDestination - override
- //----------------------------------------------------------------------------------------
-
- FW_CLinkDestination* CDrawSelection::GetLinkDestination(Environment* ev, FW_Boolean& multipleLinks)
- {
- FW_UNUSED(ev);
- // check whether any of the selected shapes is in a link destination
- FW_CLinkDestination* linkDest = NULL;
- multipleLinks = false;
-
- CDrawContentShapeIterator iter(fSelectionContent);
- for (CBaseShape* shape = iter.First(); iter.IsNotComplete(); shape = iter.Next())
- {
- if (shape->IsSubscribed())
- {
- if (linkDest == NULL)
- linkDest = shape->GetSubscribeLink(); // return the link destination
- else if (shape->GetSubscribeLink() != linkDest)
- {
- multipleLinks = true;
- return NULL;
- }
- }
- }
-
- return linkDest;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::GetSelectionPenSize
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CDrawSelection::GetSelectionPenSize(Environment* ev, FW_Fixed& penSize)
- {
- FW_UNUSED(ev);
- CDrawContentShapeIterator iter(fSelectionContent);
- FW_Boolean first = TRUE;
- for (CBaseShape *shape = iter.First(); iter.IsNotComplete(); shape = iter.Next())
- {
- if (first)
- {
- penSize = shape->GetPenSize();
- first = FALSE;
- }
- else
- {
- if (shape->GetPenSize() != penSize)
- return FALSE;
- }
- }
-
- return TRUE;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::SelectContent
- //----------------------------------------------------------------------------------------
- void CDrawSelection::SelectContent(Environment* ev, CDrawContent* content)
- {
- this->CloseSelection(ev);
-
- CDrawContentShapeIterator it(content);
- for (CBaseShape* shape = it.First(); it.IsNotComplete(); shape = it.Next())
- {
- this->AddToSelection(ev, shape, TRUE);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::GetDrawContent
- //----------------------------------------------------------------------------------------
- CDrawContent* CDrawSelection::GetDrawContent(Environment*)
- {
- return fSelectionContent;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::GetSelectedLinkSources
- //----------------------------------------------------------------------------------------
- CDrawPublishLinkCollection* CDrawSelection::GetSelectedLinkSources()
- {
- CDrawPublishLinkCollection* sources = NULL;
-
- CDrawContentShapeIterator ite(fSelectionContent);
- for (CBaseShape *shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
- {
- if (shape->IsPublished())
- {
- if (sources == NULL)
- sources = FW_NEW(CDrawPublishLinkCollection,());
-
- if (!sources->Contains(shape->GetPublishLink()))
- sources->AddLast(shape->GetPublishLink());
- }
- }
-
- return sources;
- }
-
-